package belette;

import graphics.DebugDrawable;

import java.awt.Graphics;
import java.io.Serializable;
import java.util.ArrayList;

import surface.Surface;
import utils.Vector2d;

import bots.BotManager;
import bots.IBot;

public class BeletteManager implements DebugDrawable, Serializable {
	BotManager botman;
	Surface surface;
	
	ArrayList<IBelette> beletteList;
	private ArrayList<IBelette> toDeleteList;
	
	public BeletteManager() {
		beletteList = new ArrayList<IBelette>();
		toDeleteList = new ArrayList<IBelette>();
	}
	
	public ArrayList<IBelette> getBeletteList() {
		return beletteList;
	}
	
	public void createHeartBelette(IBot firedBy, Vector2d startCoords, Vector2d velocity) {
		beletteList.add(new HeartBelette(this, firedBy, startCoords, velocity));
	}
	
	public void createLoveBeam(IBot firedBy, Vector2d startCoords, Vector2d velocity) {
		beletteList.add(new LoveBeam(this, firedBy, startCoords, velocity));
	}
	
	public void addBelette(IBelette belette) {
		beletteList.add(belette);
	}
	
	public void setBotManager(BotManager botman) {
		this.botman = botman;
	}
	
	public void setSurface(Surface surface) {
		this.surface = surface;
	}
	
	public void removeBelette(IBelette belette) {
		beletteList.remove(belette);
	}
	
	public void planForDeletion(IBelette belette) {
		toDeleteList.add(belette);
	}
	
	public void computeNextFrame() {
		if(!toDeleteList.isEmpty()) {
			beletteList.removeAll(toDeleteList);
			toDeleteList.clear();
		}
		
		for(IBelette ib : beletteList) {
			ib.computeNextFrame();
		}
	}
	
	public void drawAllOn(Graphics g) {
		for(IBelette ib : beletteList) {
			ib.draw(g);
		}
	}

	public void drawDebug(Graphics g) {
		for(IBelette ib : beletteList) {
			ib.drawDebug(g);
		}
	}
}
